/*
 * Created on 2005-9-12
 *
 *
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.dcivision.form.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dcivision.form.bean.FormRecord;
import com.dcivision.form.dao.FormRecordDAObject;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractListAction;
import com.dcivision.framework.web.AbstractSearchForm;

/**
 * @author vera
 *
 *
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ListFormMonitoringHistoryAction extends AbstractListAction {

  protected String listName = "";
  public ListFormMonitoringHistoryAction() {
    super();
    this.setListName("formMonitoringHistoryList");
    this.setListFunctionName("getFormMonitoringHistoryList");
  }

  /**
   * getMajorDAOClassName
   *
   * @return  The class name of the major DAObject will be used in this action.
   */
  public String getMajorDAOClassName() {
    return("com.dcivision.form.dao.FormSubmissionDAObject");
  }

  /**
   * getFunctionCode
   *
   * @return  The corresponding system function code of action.
   */
  public String getFunctionCode() {
    return(SystemFunctionConstant.FORM_MONITOR);
  }

  /**
   * setPageTitle
   * set the extend page title and page path.
   * default page path/title will be created by navmode and functionCode
   */
  public void setPageTitle(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping, ActionForward actionForward){
    FormRecord formRecord = (FormRecord)request.getAttribute("formRecord");
    if(!Utility.isEmpty(formRecord)){
      String extendTitle = formRecord.getTitle();
      StringBuffer extendPath = new StringBuffer();
      extendPath.append("<a href=\"ListFormMonitoringDetail.do?&formGroupID="+formRecord.getFormGroupID()+"&formRecordID="+formRecord.getID()+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"\">");
      extendPath.append(formRecord.getGroupName());
      extendPath.append("</a>");
      request.setAttribute(GlobalConstant.EXTEND_PAGE_TITLE, extendTitle);
      request.setAttribute(GlobalConstant.EXTEND_PAGE_TITLE_SHOW_ONLY, new Boolean(true));
      request.setAttribute(GlobalConstant.EXTEND_PAGE_PATH, extendPath.toString());
    }
  }

  public ActionForward execute(ActionMapping mapping,
  		ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
  throws ServletException {
  	HttpSession session = request.getSession();
  	AbstractSearchForm searchForm = (AbstractSearchForm)form;
  	String opMode = searchForm.getOpMode();
  	String navMode = searchForm.getNavMode();
  	String formRecordID = request.getParameter("formRecordID");

  	//Set Page Title
  	ListFormSubmissionForm listForm = (ListFormSubmissionForm)form;
  	FormRecordDAObject formRecordDAO = new FormRecordDAObject(this.getSessionContainer(request),this.getConnection(request));
  	FormRecord formRecord = (FormRecord)formRecordDAO.getByFormRecordID(listForm.getFormRecordID());
  	request.setAttribute("formRecord", formRecord);

  	if(!Utility.isEmpty(request.getParameter("searchSubmitter"))){
  		((ListFormSubmissionForm)searchForm).setSearchSubmitter(request.getParameter("searchSubmitter"));
  	}
  	return super.execute(mapping,form,request,response);
  }

}
